
shopping_list=[('华为p30',6800),
               ('电脑',16000),
               ('奶茶',15),
               ('披萨',88),
               ('冰淇淋',6),
               ('腾讯会员',13)]
shopping_car=[]
zhifubao=input("请输入余额：")
if zhifubao.isdigit():
    zhifubao=int(zhifubao)
    while True:
        for item in shopping_list:
            print(shopping_list.index(item),item)
        choice=input("请输入商品编号（如果不想买请输入quit退出）：")
        if choice.isdigit():
            choice=int(choice)
            if choice>=0 and choice<=5:
                if zhifubao>= shopping_list[choice][1]:
                    zhifubao = zhifubao-shopping_list[choice][1]
                    shopping_car.append(shopping_list[choice])
                    print("已为您把%s添加到购物车，您的余额还有%s。"%(shopping_list[choice][0],zhifubao))
                else:
                    print("余额不足，请充值")
            else:
                print("请输入正确商品信息：")
        elif choice == "quit":
            print("-----已购买的商品-----")
            for item in shopping_car:
                print(item)
            print("您的余额还剩%s"%zhifubao)
            break
        else:
            print("请输入商品编号:")
else:
    print("信息错误")